//
//  RecentMsgListCell.m
//  EWork
//
//  Created by administrator on 14-12-2.
//  Copyright (c) 2014年 gaobo. All rights reserved.
//

#import "RecentMsgListCell.h"

//头像大小
#define HEAD_SIZE 50.0f
//间距
#define INSETS 8.0f
//cell高和宽
#define CELL_HEIGHT self.contentView.frame.size.height
#define CELL_WIDTH self.contentView.frame.size.width

@implementation RecentMsgListCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.userHeadImage = [[UIImageView alloc]init];
        [self.userHeadImage.layer setCornerRadius:8.0f];
        [self.userHeadImage.layer setMasksToBounds:YES];
        [self.contentView addSubview:self.userHeadImage];
        
        self.userNicknameLabel = [[UILabel alloc]init];
        [self.userNicknameLabel setFont:[UIFont boldSystemFontOfSize:15]];
        [self.contentView addSubview:self.userNicknameLabel];
        
        self.msgContentLabel = [[UILabel alloc]init];
        [self.msgContentLabel setFont:[UIFont boldSystemFontOfSize:12]];
        [self.contentView addSubview:self.msgContentLabel];
        
//        self.msgNumberLabel = [[UILabel alloc]init];
//        [self.msgContentLabel setFont:[UIFont boldSystemFontOfSize:12]];
//        [self.contentView addSubview:self.msgNumberLabel];
        
        self.timeLabel = [[UILabel alloc]init];
        [self.timeLabel setFont:[UIFont boldSystemFontOfSize:15]];
        [self.contentView addSubview:self.timeLabel];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat userHeadImageX = INSETS;
    CGFloat userHeadImageY = (CELL_HEIGHT - HEAD_SIZE)/2;
    CGFloat userHeadImageWH = HEAD_SIZE;
    self.userHeadImage.frame = CGRectMake(userHeadImageX, userHeadImageY, userHeadImageWH, userHeadImageWH);
    
    CGFloat userNickNameX = 2*INSETS + userHeadImageWH;
    CGFloat userNickNameY = userHeadImageY;
    CGFloat userNickNameW = (CELL_HEIGHT - HEAD_SIZE - 4*INSETS)/2;
    CGFloat userNickNameH = (CELL_HEIGHT - 3*INSETS)/2;
    self.userNicknameLabel.frame =CGRectMake(userNickNameX, userNickNameY, userNickNameW, userNickNameH);
    
    CGFloat msgContentX = userNickNameX;
    CGFloat msgContentY = userNickNameY +userNickNameH +INSETS;
    CGFloat msgContentW = (CELL_HEIGHT - HEAD_SIZE - 4*INSETS)*0.8;
    CGFloat msgContentH = userNickNameH;
    self.msgContentLabel.frame = CGRectMake(msgContentX, msgContentY, msgContentW, msgContentH);
    
    CGFloat timeLabelX = userNickNameX + userNickNameW +INSETS;
    CGFloat timeLabelY = userNickNameY;
    CGFloat timeLabelW = userNickNameW;
    CGFloat timeLabelH = userNickNameH;
    self.timeLabel.frame = CGRectMake(timeLabelX, timeLabelY, timeLabelW, timeLabelH);
    
//    CGFloat msgNumberX = timeLabelX;
//    CGFloat msgNumberY = msgContentY;
//    CGFloat msgNumberW = (CELL_HEIGHT - HEAD_SIZE - 4*INSETS)*0.2;
//    CGFloat msgNumberH = msgContentH;
//    self.msgNumberLabel.frame = CGRectMake(msgNumberX, msgNumberY, msgNumberW, msgNumberH);
}

- (void)setUnionObject:(MessageUserUnionObject *)aUnionObj{
    [self.userHeadImage setWebImage:FILE_BASE_URL(aUnionObj.user.userHead) placeHolder:[UIImage imageNamed:@"mb.png"] downloadFlag:self.userHeadImage.tag];

    self.userNicknameLabel.text = aUnionObj.user.userNickname;
    self.msgContentLabel.text = aUnionObj.message.messageContent;
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setAMSymbol:@"上午"];
    [formatter setPMSymbol:@"下午"];
    [formatter setDateFormat:@"a HH:mm"];
    self.timeLabel.text = [formatter stringFromDate:aUnionObj.message.messageDate];

//    self.msgNumberLabel.text =
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
@end
